Gradient Boost

Before moving forward with the to-do list, let’s throw a Random Forest to it.

Gradient boost

For many reasons, Random Forest is usually a very good baseline model. In this particular case I started with the polynomial OLS as baseline model, just because it was so evident from the correlations that the relationship between temperature and consumption follows a polynomial shape. But let’s go back to a beloved RF.

Model Cards provide a framework for transparent, responsible reporting. 
 Use the vetiver `.qmd` Quarto template as a place to start, 
 with vetiver.model_card()
Writing pin:
Name: 'wd-gb'
Version: 20250102T041432Z-d7964
<vetiver.vetiver_model.VetiverModel at 0x7fbe7cbf8550>

Metrics

Single Split CV
train test test train
MAE - Mean Absolute Error 1.348045 1.972405 2.065987 1.259619
MSE - Mean Squared Error 3.519393 14.882761 9.833693 2.956194
RMSE - Root Mean Squared Error 1.876005 3.857818 2.844032 1.719204
R2 - Coefficient of Determination 0.962217 0.832338 -1.886210 0.969733
MAPE - Mean Absolute Percentage Error 0.127054 0.187528 0.332406 0.106198
EVS - Explained Variance Score 0.962217 0.837885 -0.391126 0.969733
MeAE - Median Absolute Error 0.958408 1.249821 1.495599 0.951747
D2 - D2 Absolute Error Score 0.809481 0.697134 -0.482078 0.820646
Pinball - Mean Pinball Loss 0.674022 0.986203 1.032993 0.629810

Scatter plot matrix

Observed vs. Predicted and Residuals vs. Predicted

Check for …

check the residuals to assess the goodness of fit.

  • white noise or is there a pattern?
  • heteroscedasticity?
  • non-linearity?

Normality of Residuals:

Check for …

  • Are residuals normally distributed?

Leverage

Scale-Location plot

Residuals Autocorrelation Plot

Residuals vs Time

Again, overfits a lot.

Parameter: param_model__learning_rate

Parameter: param_model__max_depth

Parameter: param_model__min_samples_leaf

Parameter: param_model__min_samples_split

Parameter: param_model__n_estimators

Parameter: param_model__subsample

Parameter: param_vars__columns

Best model

{'model__learning_rate': 0.1,
 'model__max_depth': 5,
 'model__min_samples_leaf': 5,
 'model__min_samples_split': 48,
 'model__n_estimators': 60,
 'model__subsample': 1,
 'vars__columns': ['rf_tu_mean', 'vp_std_mean']}
Pipeline(steps=[('vars', ColumnSelector(columns=['rf_tu_mean', 'vp_std_mean'])),
                ('model',
                 GradientBoostingRegressor(max_depth=5, min_samples_leaf=5,
                                           min_samples_split=48,
                                           n_estimators=60, random_state=7,
                                           subsample=1))])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.

Metrics

Single Split CV
train test test train
MAE - Mean Absolute Error 1.503511 1.976525 2.105517 1.512981
MSE - Mean Squared Error 4.823659 15.801028 7.827880 4.952713
RMSE - Root Mean Squared Error 2.196283 3.975051 2.660241 2.222937
R2 - Coefficient of Determination 0.948215 0.821993 -1.965980 0.949183
MAPE - Mean Absolute Percentage Error 0.133433 0.189170 0.359797 0.117619
EVS - Explained Variance Score 0.948215 0.831426 -0.071225 0.949183
MeAE - Median Absolute Error 1.007318 1.194803 1.729516 1.023082
D2 - D2 Absolute Error Score 0.787509 0.696502 -0.581689 0.784418
Pinball - Mean Pinball Loss 0.751756 0.988262 1.052758 0.756490

Scatter plot matrix

Observed vs. Predicted and Residuals vs. Predicted

Check for …

check the residuals to assess the goodness of fit.

  • white noise or is there a pattern?
  • heteroscedasticity?
  • non-linearity?

Normality of Residuals:

Check for …

  • Are residuals normally distributed?

Leverage

Scale-Location plot

Residuals Autocorrelation Plot

Residuals vs Time

Compare vanilla vs. tuned

Metrics

Single split

Metrics based on the test set of the single split

Cross validation

Predictions, residuals, observed

next

Time vs. Predicted and Observed

Time vs. Residuals

Model details

Pipeline(steps=[('vars',
                 ColumnSelector(columns=['tt_tu_mean', 'rf_tu_mean', 'td_mean',
                                         'vp_std_mean', 'tf_std_mean'])),
                ('model', GradientBoostingRegressor(random_state=7))])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
Pipeline(steps=[('vars', ColumnSelector(columns=['rf_tu_mean', 'vp_std_mean'])),
                ('model',
                 GradientBoostingRegressor(max_depth=5, min_samples_leaf=5,
                                           min_samples_split=48,
                                           n_estimators=60, random_state=7,
                                           subsample=1))])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.

TODOs